{extend name="sitehome@style/base"/}
{block name="resources"}
{/block}
{block name="main"}
<div class="nc-table-box">
    <table id="pay_list" lay-filter="pay_list" class="layui-table"></table>
</div>

<script type="text/html" id="title">
	<p class="img-wrap">
		<img src="{{d.info.icon}}" onerror="imgError(this)"/>
	</p>
	<span class="table-title">{{d.info.title}}</span>
</script>

<script type="text/html" id="status">
	<input type="checkbox" name="status" value="{{d.config.name}}" lay-skin="switch" lay-filter="status" {{ d.config.status==1 ? 'checked' : '' }}>
</script>

<script type="text/html" id="operation">
	<a href="{{d.info.url}}"class="default" lay-event="edit">编辑</a>
</script>
{/block}
{block name="script"}
<script>
var table = new Table({
	elem: '#pay_list',
	filter: "pay_list",
	url: '{:addon_url("Pay://sitehome/pay/lists")}',
	cols: [[{
		field: 'title',
		width: '40%',
		title: '支付方式',
		templet: '#title',
        unresize : 'true'
	}, {
		field: 'status',
		width: '40%',
		title: '状态',
		templet: '#status',
        unresize : 'true'
	}, {
		title: '操作',
		toolbar: '#operation',
		align: 'right',
        unresize : 'true'
	}]]
});

//监听工具条
table.tool(function(obj) {
	var data = obj.data;
	var event = obj.event;
	if (event === 'edit') {
		location.href = nc.url('Pay://sitehome/pay/config', {
			addon_name: data.name
		});
	}
});

function imgError(element) {
	element.src = '';
}

layui.use('form', function() {
	var form = layui.form;
	//开关监听
	form.on('switch(status)', function (data) {
		var name = data.value;
		var status = data.elem.checked ? 1 : 0;
		$.ajax({
			type: "post",
			url: '{:addon_url("Pay://sitehome/pay/setPayConfigStatus")}',
			data: {
				'status': status,
				'name': name
			},
			dataType: "JSON",
			success: function (res) {
				layer.msg(res.message);
			}
		});
		return false;
	});
});
</script>
{/block}